<template>
  <div class="divlogin">
    <el-form ref="loginformref" :model="data.form" label-width="auto" style="max-width: 300px" >
      <el-form-item label="账号：" prop="username">
        <el-input v-model="data.form.username" />
      </el-form-item>
      <el-form-item label="密码：" prop="password">
        <el-input v-model="data.form.password" type="password" />
      </el-form-item>
      <el-form-item label="邮箱：" prop="password">
        <el-input v-model="data.form.email" />
      </el-form-item>
      <el-form-item class="btns">
        <el-button type="primary" @click="login" >登录</el-button>
        <el-button type="info" @click="register" >注册</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from 'vue'
import {useRouter} from "vue-router"
import {UserLogin, UserRegister} from "@/service/user"
const router = useRouter()
const data = reactive({
  form:{
    username: '',
    password: '',
    email: '',
  }
})


const register = async() => {
  console.log(data.form)
  const res = await UserRegister(data.form)
}

const login = async() => {
  const res = await UserLogin(data.form)
  localStorage.setItem("userinfo",JSON.stringify(res.data))
  await router.push("/")
}

</script>

<style lang="scss" scoped>
.divlogin{
  margin: 60px auto;
  display: flex;
  justify-content: center;
}

.el-form-item_label{
  font-weight: bold;
}

.el-form {
  width: 100%;
  border: 1px solid rgb(100, 100, 100);
  padding: 20px;
}

::v-deep .btns .el-form-item__content{
  display: flex;
  justify-content: flex-end;
}
</style>